<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>input失去焦点和获得焦点jquery焦点事件插件</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            jQuery.focusblur = function (focusid) {
                var focusblurid = $(focusid);
                var defval = focusblurid.val();
                focusblurid.focus(function () {
                    var thisval = $(this).val();
                    if (thisval == defval) {
                        $(this).val("");
                    }
                });
                focusblurid.blur(function () {
                    var thisval = $(this).val();
                    if (thisval == "") {
                        $(this).val(defval);
                    }
                });

            };
            /*下面是调用方法*/
            $.focusblur("#searchkey");
        });
    </script>
</head>

<body>
<form action="" method="post">
    <input name="" type="text" value="输入搜索关键词" id="searchkey"/>
    <input name="" type="submit" id="searchbtn" value="搜索"/>
</form>
<p>input失去焦点和获得焦点jquery焦点事件插件，<br/><strong style="color:#F00">鼠标在搜索框中点击的时候里面的文字就消失了</strong>。</p>

</body>
</html>